import axios from '../utils/axios'
import {userinfo}from '../utils/getUserInfo'
//获取购物车商品列表
export const cartlist=async ()=>{
    const uid=userinfo().uid
    if (!uid) return false
 
    const res=await axios.get('/cartlist',{params:{uid}});
    const list=[]
    if(res.code===200){
       
        res.list.forEach(element => {
            if(!element.content) return false
            element.content.forEach(item=>{
                item.checked=true
                 list.push(item)
            })
           
        });
        
    }
    return list
}
//计算购物车数量
export const getnum=(list)=>{
    var num=0;
    list.forEach(item=>{
        num+=item.num
    })
    return num
}

//删除数据
export const cartdelete=(id)=>axios.post('/cartdelete',{id})

//添加数据
export const cartadd=(goodsid,type=1,num=1,)=>{
    const {uid}=userinfo()
   return axios.post('/cartadd',{uid,goodsid,num,type})}
